#ifndef __COMMON_H__
#define __COMMON_H__

#include <string.h>

#define _(String) (String)//gettext(String)

#define LIBUSB_EXIT 1//1: libusb已安装，0: libusb未安装

//#define OFP_LOG_FILE_NAME "/usr/lib/biometric-authentication/drivers/extra/ofprint2686/log_ofp.txt"
#define OFP_LOG_FILE_NAME "/usr/share/deepin-authentication/modes/ofprint2686-serverd/log_ofp.txt"
//#define OFP_LOG_FILE_NAME "/opt/apps/ofilm.oms.Ofprint/files/conf/log_ofp.txt"

#define LOG_FILE_SIZE_MAX       (10 * 1024 * 1024)//预留log存储大小
#define PRINT_LOG_MAX_SIZE_1024 2500
#define PRINT_LOG_MAX_SIZE_300  1200


#define _DBG_   //开启调试输出，屏蔽则关输出
#define _ERR_   //开启错误输出，屏蔽则关输出
#define _LOG_   //开始关键信息输出，屏蔽则关输出

#ifdef _DBG_
#define DBG(...) printf(__VA_ARGS__)
#else
#define DBG(...)
#endif

#ifdef _ERR_
#define ERR(...) printf(__VA_ARGS__)
#else
#define ERR(...)
#endif

#ifdef _LOG_
#define LOG(...) printf(__VA_ARGS__)
#else
#define LOG(...)
#endif

#define D_DBG(...)  \
    DBG("[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
    DBG(__VA_ARGS__)

#define D_ERR(...)  \
    ERR("[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
    ERR(__VA_ARGS__)

#define D_LOG(...)  \
    LOG("[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
    LOG(__VA_ARGS__)

typedef enum _LOG_GRADE_ENUM_
{
    ERR_LOG_GRADE = 1,
    LOG_LOG_GRADE = 2,
    DBG_LOG_GRADE = 3,
}LOG_GRADE_ENUM;

extern int ofp_print_log(char *buf, int len, LOG_GRADE_ENUM grade);
extern int ofp_print_log_time(char *buf, int len, LOG_GRADE_ENUM grade);

//简单输出信息
#define W_LOG(fmt, ... ) \
    {\
        char dbg_info[PRINT_LOG_MAX_SIZE_1024] = {0};\
        snprintf(dbg_info, PRINT_LOG_MAX_SIZE_1024, fmt, ##__VA_ARGS__);\
        ofp_print_log(dbg_info, strlen(dbg_info), LOG_LOG_GRADE);\
        LOG("%s", dbg_info);\
    }

#define W_DBG(fmt, ... ) \
    {\
        char dbg_info[PRINT_LOG_MAX_SIZE_1024] = {0};\
        snprintf(dbg_info, PRINT_LOG_MAX_SIZE_1024, fmt, ##__VA_ARGS__);\
        ofp_print_log(dbg_info, strlen(dbg_info), DBG_LOG_GRADE);\
        DBG("%s", dbg_info);\
    }

#define W_ERR(fmt, ... ) \
        {\
            char dbg_info[PRINT_LOG_MAX_SIZE_1024] = {0};\
            snprintf(dbg_info, PRINT_LOG_MAX_SIZE_1024, fmt, ##__VA_ARGS__);\
            ofp_print_log(dbg_info, strlen(dbg_info), ERR_LOG_GRADE);\
            ERR("%s", dbg_info);\
        }

//输出时间戳、文件、行号、函数
#define WD_LOG(fmt, ... ) \
    {\
        char dbg_msg_log[PRINT_LOG_MAX_SIZE_1024] = {0};\
        char dbg_info[PRINT_LOG_MAX_SIZE_300] = {0};\
        snprintf(dbg_msg_log, PRINT_LOG_MAX_SIZE_300, "[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
        snprintf(dbg_info, PRINT_LOG_MAX_SIZE_300, fmt, ##__VA_ARGS__);\
        strcat(dbg_msg_log, dbg_info);\
        ofp_print_log_time(dbg_msg_log, strlen(dbg_msg_log), LOG_LOG_GRADE);\
        LOG("%s", dbg_msg_log);\
    }

#define WD_ERR(fmt, ... ) \
    {\
        char dbg_msg_log[PRINT_LOG_MAX_SIZE_1024] = {0};\
        char dbg_info[PRINT_LOG_MAX_SIZE_300] = {0};\
        snprintf(dbg_msg_log, PRINT_LOG_MAX_SIZE_300, "[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
        snprintf(dbg_info, PRINT_LOG_MAX_SIZE_300, fmt, ##__VA_ARGS__);\
        strcat(dbg_msg_log, dbg_info);\
        ofp_print_log_time(dbg_msg_log, strlen(dbg_msg_log), ERR_LOG_GRADE);\
        ERR("%s", dbg_msg_log);\
    }

#define WD_DBG(fmt, ... ) \
    {\
        char dbg_msg_log[PRINT_LOG_MAX_SIZE_1024] = {0};\
        char dbg_info[PRINT_LOG_MAX_SIZE_300] = {0};\
        snprintf(dbg_msg_log, PRINT_LOG_MAX_SIZE_300, "[%s:%d:%s] ", __FILE__, __LINE__, __func__);\
        snprintf(dbg_info, PRINT_LOG_MAX_SIZE_300, fmt, ##__VA_ARGS__);\
        strcat(dbg_msg_log, dbg_info);\
        ofp_print_log_time(dbg_msg_log, strlen(dbg_msg_log), DBG_LOG_GRADE);\
        DBG("%s", dbg_msg_log);\
    }




#define DRV_OK      (0)
#define DRV_ERR     (-1)

#define uint8 unsigned char
#define int8 char

#define uint16 unsigned short int
#define int16 short int

#define uint32 unsigned int
#define int32 int


extern int com_check_file_exit(char *file_path, int size_min, int size_max);
extern int com_get_file_size(char *filename);
extern uint8 com_Check_BCC(uint8 *data, int len);
extern unsigned short com_CRC16_X25(char *data, unsigned int datalen);
extern int com_compare_array(uint8 *src, uint8 *dst, int len);



#endif

